<?php

class DefaultSidebarPanel
{
    protected $seed = null;
    
    public function __construct($seed = null)
    {
        if (!is_null($seed))
        {
            $this->seed = $seed;
        }
    }
  
    public function GetContent($panelInfo, TemplateEngine $tmpl, $pageId)
    {
        return $this->GetGeneratedContent($panelInfo, $tmpl, $pageId);
    }
 
    protected function Generate( $template, TemplateEngine $tmpl, $tmplVars = null )
    {
        $tmpl->define("panel", $template);
        /* Set special sidebar var to template */
        if (!is_null($tmplVars) && is_array($tmplVars))
        {
            foreach ($tmplVars as $key => $value)
            {
              $tmpl->set($key, $value);
            }
        }
        $tmpl->parse("content", "panel");
        return $tmpl->getGenerated();
    }
    
    protected function GetGeneratedContent( $panelInfo, TemplateEngine $tmpl, $pageId )
    {
        $cacheId = "html/_sidebar_panels/". $panelInfo['id'];
        return $this->GenerateContent($cacheId, $panelInfo, $tmpl);
    }
    
    protected function GenerateContent($cacheId, $panelInfo, $tmpl, $tmplVar = null)
    {
        $content = Core::Cache()->Get($cacheId);
        if ( empty($content) )
        {
            $content = $this->Generate( $panelInfo['template'], $tmpl, $tmplVar );
            Core::Cache()->Set($cacheId, $content);
        }
        
        return $content;
    }

}

?>
